﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 面向对象版聊天机器人
{
    class Program
    {
        static void Main(string[] args)
        {
            Robot r1 = new Robot();
            r1.Name = "小猪";
          //  r1.SayHello();
            r1.Eat(5);

            Robot r2 = new Robot();
            r2.Name = "小鸟";
        //    r2.SayHello();
            r2.Eat(8);

   /*         Robot r = r1;
            r1 = r2;
            r.SayHello();*/

            Console.WriteLine("请选择你将要交谈的机器人，1-小猪，2-小鸟");
            string rr = Console.ReadLine();
            Robot rx;
            if ("1" == rr)
            {
                rx = r1;
            }
            else if ("2" == rr)
            {
                rx = r2;
            }
            else
            {
                return;
            }
            rx.SayHello();
            while (true)
            {
                string str = Console.ReadLine();
                rx.Speak(str);
            }
            Console.ReadKey();
        }
    }

    class Robot
    {
        public string Name { get; set; }

        private int FullLevel { get; set; }

        public void SayHello()
        {
            Console.WriteLine("你好,我叫{0}",Name);
        }

        public void Eat(int foodCount)
        {
            if (FullLevel >= 100)
            {
                return;
            }
            FullLevel += foodCount;
        }

        public void Speak(string str)
        {
            if (FullLevel <= 0)
            {
                Console.WriteLine("饿死了,没力气跟你说了！");
                return;
            }
            else if (str.Contains("你好"))
            {
                Console.WriteLine("你好！");
            }
            else if (str.Contains("叫什么") || str.Contains("名字"))
            {
                Console.WriteLine("我叫{0}", Name);
            }
            else if (str.Contains("女朋友"))
            {
                Console.WriteLine("我还小，暂时不考虑这事儿！");
            }
            else
            {
                Console.WriteLine("你说的什么，我听不懂！");
            }
            FullLevel--;
        }

    }
}
